package design.pattern.Lu20StatePattern;

/**
 * @program JavaBase
 * @description:
 * @author: zhanglu
 * @create: 2020-05-17 20:10:00
 */
public class StatePattern02 {

    public static void main(String[] args) {
        Context02 context02 = new Context02();
        context02.setState02(Context02.concreateState021);
        context02.handle01();
    }

}

abstract class State02{
    protected Context02 context02;
    public void setContext02(Context02 context02){
        this.context02 = context02;
    }
    //行为1
    protected abstract void handle01();
    //行为02
    protected abstract void hanlde02();
}

class ConcreateState021 extends State02{

    @Override
    protected void handle01() {
        System.out.println("handle01处理逻辑");
    }

    @Override
    protected void hanlde02() {
        super.context02.setState02(Context02.concreateState022);
        super.context02.handle02();
    }
}

class ConcreateState022 extends State02{

    @Override
    protected void handle01() {
        super.context02.setState02(Context02.concreateState021);
        super.context02.handle02();
    }

    @Override
    protected void hanlde02() {
        System.out.println("handle02处理逻辑");
    }
}

class Context02{
    public final static State02 concreateState021 = new ConcreateState021();
    public final static State02 concreateState022 = new ConcreateState022();

    private State02 state02;

    public void setState02(State02 state02){
        this.state02 = state02;
        this.state02.setContext02(this);
    }

    public State02 getState02(){
        return this.state02;
    }

    public void handle01(){
        this.state02.handle01();
    }

    public void handle02(){
        this.state02.hanlde02();
    }

}

